package com.danskin.wechat.util;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;

public class PropertyUtil {
 
	
	private static ResourceBundle bundle;
	private static BufferedInputStream inputStream;
	static {
		String catalinaHome = System.getProperty("catalina.home");
		if (catalinaHome == null) {
			catalinaHome = "";
		}
		String proFilePath = catalinaHome + File.separator + "conf" + File.separator + "application.properties";
		try {
			inputStream = new BufferedInputStream(new FileInputStream(proFilePath));
			bundle = new PropertyResourceBundle(inputStream);
			inputStream.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 获取ServletContext内容
	 * 
	 * @param key
	 * @return
	 */
	public static final String get(String key) {
		// LOG.info("=====================获取ServletContext内容：" +
		// bundle.getString(key));
		// LOG.info("=================================================" +
		// System.getProperty("profilesName"));
		return bundle.getString(key);
	}

	/**
	 * 拼装前端链接
	 * 
	 * @param appId
	 * @param redirectName
	 * @return
	 */
	public static final String getFrontUrl(String appId, String redirectName) {

		return get("front_domain") + "/route.html?appid=" + appId + "&wxredirectname=" + redirectName;
	}

}
